package org.acompanhamento.dao;

import java.util.List;

import org.acompanhamento.domain.Member;
import org.acompanhamento.domain.Sprint;
import org.acompanhamento.domain.Status;
import org.acompanhamento.domain.Task;
import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

import bancosys.tec.persist.dao.BaseDAO;
import bancosys.tec.persist.hibernate.RestrictionsUtils;
import bancosys.tec.utils.date.Date;

/**
 * 
 * @author icaro.kume
 *
 */
public class TaskDAO extends BaseDAO<Task> {

	// Buscar por palavra chave, tanto na descri����o como no resumo, se aparecer
	// em um ou outro, retorna
	// um campo de busca gen��rico?
	public List<Task> findBy(String identifier, String description, String summary, Long points, Sprint sprint,
			Status status, Member responsible, Date recordDate){
		Criteria criteria = this.createCriteria();
		RestrictionsUtils.addRestrictionLike(criteria, "identifier", identifier, MatchMode.ANYWHERE);
		RestrictionsUtils.addRestrictionLike(criteria, "description", description, MatchMode.ANYWHERE);
		RestrictionsUtils.addRestrictionLike(criteria, "summary", summary, MatchMode.ANYWHERE);
		RestrictionsUtils.addRestrictionEq(criteria, "points", points);
		RestrictionsUtils.addRestrictionEqId(criteria, "sprint.id", sprint);
		RestrictionsUtils.addRestrictionEqId(criteria, "status.id", status);
		RestrictionsUtils.addRestrictionEqId(criteria, "responsible.id", responsible);
		RestrictionsUtils.addRestrictionEq(criteria, "recordDate", recordDate);
		return this.executeQuery(criteria);
	}

	public List<Task> findBySprintStatus(Sprint sprint, Status status){
		Criteria criteria = this.createCriteria();
		criteria.add(Restrictions.eq("sprint", sprint));
		criteria.add(Restrictions.eq("status", status));
		return this.executeQuery(criteria);
	}
}
